package com.dingqb.ndkproject;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.dingqb.ndkproject.nativelib.Jni;
import com.dingqb.ndkproject.nativelib.ww;
import com.dingqb.ndkprojectjni.qq;

import java.sql.Array;
import java.util.Arrays;
import java.util.Collections;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    static {
        System.loadLibrary("ww");// 本地生成的so文件
        System.loadLibrary("qq");// 第三方提供的so文件
    }

    private TextView tv_local_add;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        showJniMethod();
    }

    void initView() {
        tv_local_add = (TextView) findViewById(R.id.tv_local_add);
    }

    void showJniMethod() {
        tv_local_add.setText("第三方提供的so文件：qq.add===" + qq.add(101, 202));
        TextView tv = (TextView) findViewById(R.id.sample_text);
        tv.setText("本地ndk" + ww.stringFromJNI() + ",a+b===" + ww.add(11.1f, 22.2f));
        ww.getName();
        float result = ww.mulit(52, 10);
        Log.e(TAG, "showJniMethod: " + result);
        ww.var();
        String s = Jni.showPersonName();
        Log.e(TAG, "showJniMethod: person Name====" + s);
        String s2 = Jni.replacePersonName("replace");
        Log.e(TAG, "showJniMethod: replacePersonName====" + s2);
        // 数组相关
        String[] arrays = Jni.returnStringArray();
        if (arrays != null) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arrays.length; i++) {
                sb.append(arrays[i]);
            }
            Log.e(TAG, "onCreate: returnStringArray=========================" + sb.toString());
        }
        // String
        String[] stringArray = {
                "I ",
                "am ",
                "dingqb ",
                "from ",
                "MainActivity",
        };
        Jni.stringArray(stringArray);
        float[] floatArray = {10.1f, 11.1f, 12.1f, 13.1f};
        Jni.floatArray(floatArray);
        Jni.booleanValue(false);
        int selfInt = ww.returnSelf(28);
        Log.e(TAG, "showJniMethod: returnSelf====" + selfInt);
        String selfString = ww.returnSelfString("this is self String.");
        Log.e(TAG, "showJniMethod: selfString==" + selfString);
        String[] re = Jni.returnSringArray(stringArray);
        if (re != null) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < re.length; i++) {
                sb.append(re[i]);
            }
            Log.e(TAG, "showJniMethod: returnSringArray==" + sb.toString());
        }
        Log.e(TAG, "showJniMethod: num==" + new Jni().getJavaIntField());
        Log.e(TAG, "showJniMethod: tag==" + new Jni().getJavaField());
        Log.e(TAG, "showJniMethod: new tag values ==" + new Jni().TAG);
        Log.e(TAG, "showJniMethod: 非静态方法获取java静态属性值 ==" + new Jni().getstaticJavaField());
        Log.e(TAG, "showJniMethod: 静态方法获取java静态属性值 ==" + Jni.staticMethod());
        Log.e(TAG, "showJniMethod: 静态方法获取java非静态属性值 ==" + Jni.staticMethodNotStaticField());

        // cpp类问题，通不过
//        Food food = new Food("面包", 15);
//        String name = food.getName();
//        double price = food.getPrice();
//        Log.e(TAG, "onCreate: Food: name==" + name + ";price==" + price);

    }

}
